package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(20);not null;index:ip_idx"`
	Password string `gorm:"type:varchar(36);not null;index:ip_idx"`
	Status   string `gorm:"type:enum('冻结','正常');not null;index:ip_idx"`
}

func (u *User) Create() error {
	return DB.Create(&u).Error
}

func (u *User) Find(Username string) {
	DB.Where("username=?", Username).Find(&u)
}

func (u *User) List(status string) (user []*User) {
	if status == "" {
		DB.Debug().Find(&user)
	} else {
		DB.Debug().Where("status", status).Find(&user)
	}
	return
}

func (u *User) UserStatus(id int, status string) error {
	return DB.Model(User{}).Where("id=?", id).Update("status", status).Error
}
